<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-Long-admin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
      <link href="X-admin/css/font.css" th:href="@{/X-admin/css/font.css}" rel="stylesheet" type="text/css">
      <link href="X-admin/css/xadmin.css" th:href="@{/X-admin/css/xadmin.css}" rel="stylesheet" type="text/css">

      <script type="text/javascript" th:attr="src=@{/X-admin/lib/jquery-3.2.1.min.js}"></script>
      <script type="text/javascript" th:attr="src=@{/X-admin/lib/layui/layui.js}"></script>
      <script type="text/javascript" th:attr="src=@{/X-admin/js/xadmin.js}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">


            <div class="layui-form-item">
                <label for="L_id" class="layui-form-label">
                    <span class="x-red">*</span>ID
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_id" name="id" required="" lay-verify="id" th:value="${role.id}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
          <div class="layui-form-item">
              <label for="L_name" class="layui-form-label">
                  <span class="x-red">*</span>角色名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="L_name" name="name" required="" lay-verify="name" th:value="${role.name}"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  以ROLE_对应资源_所属操作
              </div>
          </div>
            <div class="layui-form-item">
                <label for="L_alias" class="layui-form-label">
                    <span class="x-red">*</span>角色别名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_alias" name="alias" required="" lay-verify="alias" th:value="${role.alias}"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    授权的时候别名显示
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_pid" class="layui-form-label">
                    <span class="x-red">*</span>父级角色
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_pid" name="pid" required="" lay-verify="pid"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <button  class="layui-btn" onclick="x_admin_show('选择父级','/roleController/pidPage',300,450)"><i class="layui-icon"></i>选择</button>
                </div>
            </div>
        <div class="layui-form-item">
            <label for="L_remark" class="layui-form-label">
                <span class="x-red">*</span>角色描述
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_remark" name="remark" required="" lay-verify="remark" th:value="${role.remark}"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                最好加上描述，防止角色名不能见名知意
            </div>
        </div>


          <div class="layui-form-item">
              <label for="L_btn" class="layui-form-label">
              </label>
              <button  id="L_btn" class="layui-btn" lay-filter="add" lay-submit="">
                  编辑
              </button>
          </div>
      </form>
    </div>
    <script>
      layui.use(['form','layer'], function(){
          $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer;
      
        //自定义验证规则
        form.verify({
            name: [/^(ROLE_[A-Z_]+)$/, '角色名称必须是大写ROLE_开头，且是大写字母和_']
            ,remark: function(value){
                if(value.length < 5){
                    return '描述至少得5个字符';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function(data){
          console.log(data);
          //发异步，把数据提交给
        $.ajax({
            type: 'POST',
            url: "/roleController/edit",
            data: data.field,
            success: function (result) {
                if (result.success){
                    layer.alert("编辑成功", {icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        parent.location.reload();
                    });
                }else{
                    layer.msg(result.msg,function(){

                    });
                }
            },
            dataType: "json"
        });
          return false;
        });
        
        
      });
  </script>

  </body>

</html>